package com.ss.android.article.base.feature.app.d;

import com.bytedance.common.utility.Logger;
import com.ss.android.action.b.ImpressionHelper;
import com.ss.android.action.b.a;
import com.ss.android.action.b.FeedViewHolder;
import com.ss.android.common.app.LifeCycleMonitor;

import java.util.ArrayList;
import java.util.List;

public final class ImpressionListAdapter implements a, LifeCycleMonitor {
    public String a;
    public final com.ss.android.action.b.b b;
    public List c;
    private int d;
    private int e;
    private boolean f;
    private List g;
    private List h;
    private boolean i;

    public ImpressionListAdapter(String arg5, String arg6) {
        if (Logger.debug()) {
            Logger.d("ImpressionListAdapter", "ImpressionListAdapter :" + arg5);
        }
        this.a = arg5;
        this.c = new ArrayList();
        this.b = ImpressionHelper.getInstance().a(4, arg5, arg6);
        this.f = false;
        this.d = 0;
        this.e = 0;
        this.g = new ArrayList();
        this.h = new ArrayList();
        this.i = true;
    }

    public final void a(int arg6) {
        if (arg6 > 0) {
            int v1 = this.c.size();
            if (v1 < arg6) {
                int v0;
                for (v0 = v1; v0 < arg6; ++v0) {
                    FeedViewHolder v2 = new FeedViewHolder();
                    v2.a(31, String.valueOf(v0));
                    this.c.add(v2);
                }

                if (v1 == 0) {
                    this.g.add(Integer.valueOf(0));
                    this.getView();
                }
            }
        }
    }

    public final boolean a() {
        return this.i;
    }

    public final boolean a(int arg3, FeedViewHolder arg4) {
        return this.g.contains(Integer.valueOf(arg3));
    }

    public final List b() {
        return this.c;
    }

    public final void onMovedToScrapHeap(int arg4) {
        if (arg4 >= 0 && (arg4 != this.d || this.e == this.d)) {
            this.g.clear();
            this.h.clear();
            int v0 = arg4 + 1;
            if (arg4 < this.d) {
                this.g.add(Integer.valueOf(arg4));
                this.h.add(Integer.valueOf(this.e));
                if (v0 < this.d) {
                    this.g.add(Integer.valueOf(v0));
                    this.h.add(Integer.valueOf(this.d));
                }
            } else if (arg4 > this.d) {
                this.g.add(Integer.valueOf(v0));
                this.h.add(Integer.valueOf(this.d));
                if (arg4 > this.e) {
                    this.g.add(Integer.valueOf(arg4));
                    this.h.add(Integer.valueOf(this.e));
                }
            } else {
                this.g.add(Integer.valueOf(arg4));
                this.g.add(Integer.valueOf(arg4 + 1));
            }

            this.getView();
            if (this.i) {
                if (Logger.debug()) {
                    Logger.d("ImpressionListAdapter", "onMovedToScrapHeap : " + this.h.toString());
                }

                if (this.h.isEmpty()) {
//                    goto label_98;
                } else {
                    int v1;
                    for (v1 = 0; v1 < this.h.size(); ++v1) {
                        v0 = ((Integer) this.h.get(v1)).intValue();
                        if (v0 >= 0 && v0 < this.c.size()) {
                            Object v0_1 = this.c.get(v0);
                            if (v0_1 != null && (((FeedViewHolder) v0_1).n_())) {
                                this.b.b(((FeedViewHolder) v0_1));
                            }
                        }
                    }

                    this.h.clear();
                }
            }

            label_98:
            this.d = arg4;
            this.e = arg4 + 1;
        }
    }

    public final void onDestroy() {
        this.i = false;
    }

    public final void onResume() {
        if (Logger.debug()) {
            Logger.d("ImpressionListAdapter", "onResume :" + this.a);
        }

        this.i = true;
        if (this.b != null) {
            this.b.a(this);
            this.f = false;
        }
    }

    private void getView() {
        if (this.i) {
            if (Logger.debug()) {
                Logger.d("ImpressionListAdapter", "getView : " + this.g.toString());
            }

            if (this.g.isEmpty()) {
                return;
            }

            int v1;
            for (v1 = 0; v1 < this.g.size(); ++v1) {
                int v0 = ((Integer) this.g.get(v1)).intValue();
                if (v0 >= 0 && v0 < this.c.size()) {
                    Object v0_1 = this.c.get(v0);
                    if (v0_1 != null && !((FeedViewHolder) v0_1).n_()) {
                        this.b.a(((FeedViewHolder) v0_1));
                    }
                }
            }
        }
    }

    public final void onPause() {
        if (Logger.debug()) {
            Logger.d("ImpressionListAdapter", "onPause :" + this.a);
        }

        this.i = false;
        if (!this.f && this.b != null) {
            this.b.b(this);
            this.f = true;
        }
    }

    public final void onStop() {
        this.i = false;
        this.g.clear();
        this.h.clear();
        this.c.clear();
    }
}

